In [3]:
%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from scipy.constants import physical_constants
from scipy.optimize import curve_fit
import h5py

Plot Settings


In [4]:
matplotlib.rcParams['savefig.dpi'] = 144
matplotlib.rcParams['savefig.transparent'] = True
matplotlib.rcParams['axes.facecolor'] = '#444444'
matplotlib.rcParams['axes.edgecolor'] = 'white'
matplotlib.rcParams['axes.labelcolor'] = 'white'
matplotlib.rc('xtick',color='w')
matplotlib.rc('ytick', color='w')

T1 Fit, Plot


In [8]:
def t1ft(x, p0,p1,p2):
        return (p0*np.exp(-x/p1)+p2)
def t1(xD, yD):
    popt, pcov = curve_fit(t1ft, xD, yD, p0=(np.amin(yD)-np.amin(yD),np.amax(xD)/3,yD[-1]))
    fitY = t1ft(xD,popt[0],popt[1],popt[2])
    fres = sum((yD-fitY)**2)
    t1str = ("T1=" + str(popt[1]/1e3) + " $\mu s$")
    print("Residuals " + str(fres))
    print("Covariance Matrix" + str(pcov))
    plt.plot(x/1e3,y, 'ro', x/1e3,fitY)
    plt.title(t1str, color='white')
    plt.xlabel('$\mu s$')
    return popt, pcov, fitY, fres

Import Data


In [6]:
def getData(filename):
    
    f = h5py.File(filename)
    y = np.power(f['DataSet1']['real'][:],2) + np.power(f['DataSet1']['imag'][:],2)
    x = f['DataSet1']['xpoints'][:]
    return [x, np.asfarray(y, dtype=np.float64)]

In [9]:
[xD,yD]=getData('555_SH_Hero_T1_26db_0.2amp.h5')
# Trim off last 4 points, they are noisy
x=xD[0:-4]
y=yD[0:-4]
#Calculate T1
results = t1(x,y)


Residuals 1.11726313783e-13
Covariance Matrix[[ inf  inf  inf]
 [ inf  inf  inf]
 [ inf  inf  inf]]

In [ ]: